package top.majuan.springboot3.controller.lianxi;

import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.majuan.springboot3.annotation.Limit;
import top.majuan.springboot3.base.PageBean;
import top.majuan.springboot3.base.R;
import top.majuan.springboot3.entity.lianxi.TbContact;
import top.majuan.springboot3.service.lianxi.Contact.TbContactService;
import top.majuan.springboot3.validate.CommonValidate;
import top.majuan.springboot3.vo.PageVo;

@RestController
@RequestMapping("/contact")
@RequiredArgsConstructor
public class TbContactController {
     private final TbContactService tbContactService;
    @Limit(key = "/contact/insert", message="不要频繁添加")
    @PostMapping("")
    public R<String> insert(@RequestBody @Validated(CommonValidate.Add.class) TbContact tbContact)
    {
        return tbContactService.insert(tbContact);
    }
    @GetMapping("/{ps}/{pn}")
    public R<PageVo<TbContact>> query(TbContact tbContact, @PathVariable("ps") Long ps, @PathVariable("pn") Long pn)
    {
        return tbContactService.query(tbContact, PageBean.instance(pn, ps));
    }
    @PutMapping("")
    public R<String> update(@RequestBody @Validated(CommonValidate.Edit.class) TbContact tbContact) {
        return tbContactService.update(tbContact);
    }

    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable("id") Integer id) {
        return tbContactService.delete(id);
    }
    @GetMapping("/{id}")
    public R<TbContact> queryByid(@PathVariable("id") Integer id) {
        return tbContactService.queryByid(id);
    }
}
